/**
 * Created by xiebang
 * Description
 * User:小谢
 * Date:2021-09-26
 * Time:20:49
 */
class Node{
    public int data;
    public Node next;

    public int getData() {
        return data;
    }

    public Node(int data) {
        this.data = data;
    }
}
public class MyQueue {
    private Node front;
    private Node rear;
    private int usedSize;

    /**
     * 入队列
     * @param val 值
     */
    public void offer(int val) {
        Node node = new Node(val);
        if (this.front == null){
            this.front = node;
            this.rear = node;
        }else {
            this.rear.next = node;
            this.rear = node;
        }
        this.usedSize++;
    }

    /**
     * 出队头元素
     * @return
     */
    public int poll() throws RuntimeException{
        if (isEmpty()){
            throw new RuntimeException("队列为空");
        }
        int val = this.front.getData();
        if (this.front.next == null){
            this.front = null;
            this.rear = null;
        }else {
            this.front = this.front.next;
        }
        this.usedSize--;
        return val;
    }

    /**
     * 得到队头元素 但是不删除
     */
    public int  peek() {
        if (isEmpty()){
            throw new RuntimeException("队列为空");
        }
        return this.front.getData();
    }

    public boolean isEmpty() {

        return this.usedSize == 0;
    }

    public int size() {
        return this.usedSize;
    }
}
